#include "tcp_server.hpp"
#include "daemon.hpp"
#include <memory>

using namespace ns_server;

static void usage(std::string proc)
{
    std::cout << "Usage:\n\t" << proc << "serverport\n"
              << std::endl;
}

static std::string echo(const std::string& msg)
{
    return msg;
}

// ./tcp_server port
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        usage(argv[0]);
        exit(USAGE_ERR);
    }

    std::cout << "Hello server.\n";
    uint16_t port = atoi(argv[1]);
    std::unique_ptr<TCPServer> pts(new TCPServer(echo, port));
    pts->initServer();


    //将服务器守护进程化
    Daemon();

    pts->start();
    return 0;
}